import { PageContainer } from '@ant-design/pro-components';
import { useDispatch, useSelector } from '@umijs/max';
import { useEffect, useState } from 'react';
import AdminForm from './components/adminForm';
import style from './css/admin.module.css';
export default function AddAdmin() {
  const [initData, setInitData] = useState({
    permission: 2,
  });
  const dispatch = useDispatch();
  const { adminList } = useSelector((state) => {
    return state.admin;
  });
  useEffect(() => {
    // 看一下当前的数据仓库有没有列表数据
    if (adminList.length > 0) {
      //
      return;
    } else {
      dispatch({ type: 'admin/_initList' });
    }
  }, []);
  function submit(target) {
    dispatch({
      type: 'admin/_addAdmin',
      payload: target,
    });
  }
  return (
    <>
      <PageContainer
        header={{
          breadcrumb: {
            items: [
              {
                title: '管理员',
              },
              {
                title: '新增管理员',
              },
            ],
          },
        }}
      >
        <div className={style.formcontainer}>
          <AdminForm type="add" initData={initData} submit={submit} />
        </div>
      </PageContainer>
    </>
  );
}
